/*
 * KP ebdesk
 */

package com.ebdesk.controller.masterdata;

import com.ebdesk.model.masterdata.User;
import com.ebdesk.model.masterdata.database.DatabaseData;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author Zulfikar <zulfikarfull@gmail.com>
 */
public abstract class Authentication {
    public static boolean validation(String username, String password) throws ClassNotFoundException, IOException, SQLException, NullPointerException {
        UserManagement um = new UserManagement();
        
        
        User user = um.getUser(username);
        if (user.getUsername() == null)
            return false;

        DatabaseData db = new DatabaseData();
        ResultSet rs = db.queryData("select md5('" + password + "')");
        String pwk = "";
        while (rs.next()) {
            pwk = rs.getString(1);
        } 
        
        if (username.equals(user.getUsername()) && pwk.equals(user.getPassword()))
                return true;
        else return false;
    }
}
